package com.ymatou.iapi.sellerproduct.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerproduct.parameter.ActivityProductSaleBean;
import com.ymatou.iapi.sellerproduct.service.ActivityProductStartSaleCall;
import com.ymatou.iapi.sellerproduct.service.SetRecommendCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.NewJavaMongoCheckService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.mongo.LiveProductInfoWapper;
import com.ymttest.database.mongo.LiveProductModelWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.LiveProductsWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsInLiveWapper;
import com.ymttest.utils.EnvSetup;
/**
*置顶商品
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetRecommend{
	private static SetRecommendCall setrecommendCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("置顶商品");
	}

	@Before
	public void caseUp() {
		setrecommendCall=new SetRecommendCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setrecommendCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_001() {
		Logger.start(true,"置顶商品");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
			
			//断言
			SetRecommendCall.setrecommendGetreturncode(dataStr);
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(1, istopstatus, "校验SQL中是否置顶状态");
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(1, coutistop, "校验置顶商品数量");
			//Mango
//	        JSONObject aa=GetProductInfoByProductIdCall.GetProductInfoByProductId(productID);
//			JSONObject resultbymango = aa.getJSONObject("Data").getJSONObject("Product");
//			Boolean istopbymango = resultbymango.getJSONObject("LiveProduct").getBoolean("IsTop");
//			Logger.verifyEquals(true, istopbymango, "校验mango中是否置顶状态");
			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}	
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productID,false);
			}	
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetRecommend_002() {
		Logger.start(true,"待销售商品置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个即将开始的直播
			int activityId =createLiveInFuture( sellerId,  sellerName);
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);
			
			//断言
			SetRecommendCall.setrecommendGetreturncode(dataStr);
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(1, istopstatus, "校验SQL中是否置顶状态");
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(1, coutistop, "校验置顶商品数量");
			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}	
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productID,false);
			}	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetRecommend_003() {
		Logger.start(true,"暂停销售商品置顶后再次开始销售");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			//直播中暂停销售
			SellerProductCallService.suspendSaleProductInLive(sellerId, activityId, productID);
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);
			//重新开始销售
			productStartSale(sellerId, activityId, productID);
			
			//断言
			SetRecommendCall.setrecommendGetreturncode(dataStr);
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");	//1置顶 0不置顶
			Logger.verifyEquals(1, istopstatus, "校验SQL中是否置顶状态");
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(1, coutistop, "校验置顶商品数量");
			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
				
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productID,false);
			}	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_004() {
		Logger.start(false,"已置顶再次置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
			//断言
			SetRecommendCall.setrecommendGetreturncode(dataStr);
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(1, istopstatus, "校验SQL中是否置顶状态");
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(1, coutistop, "校验置顶商品数量");

			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMongo
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "校验oldmango中是否置顶状态");			
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productID,false);
			}	
			
			//已置顶再次执行置顶操作
			JSONObject dataStr2 = SetRecommendCall.setrecommendcall(calldate);
			SetRecommendCall.setrecommendGetreturnerrcode(dataStr2,201, 2012104 ,"此商品已经是推荐商品");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_005() {
		Logger.start(false,"置顶第11个商品");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布个立即上架商品
			List<String> productList = new ArrayList<>();
			for(int i=0;i<11;i++){
				productList.add(addNewProductOnSale(sellerId,sellerName));
			}
			
			//将商品添加到直播
			productList.forEach(ele->{
				try {
					SellerProductCallService.addProductInLive(sellerId, activityId, ele);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			});
			
			
			//置顶商品
			for(int i=0;i<productList.size()-1;i++){
				Map<String,Object> calldate1 = new HashMap<String, Object>();
				calldate1.put("UserId", sellerId);
				calldate1.put("ActivityId", activityId);
				calldate1.put("ProductId", productList.get(i));
				JSONObject dataStr1 = SetRecommendCall.setrecommendcall(calldate1);			
				SetRecommendCall.setrecommendGetreturncode(dataStr1);
			}
			
			
			
			
			//置顶第11个商品
			Map<String,Object> calldate4 = new HashMap<String, Object>();
			calldate4.put("UserId", sellerId);
			calldate4.put("ActivityId", activityId);
			calldate4.put("ProductId", productList.get(productList.size()-1));
			JSONObject dataStr4 = SetRecommendCall.setrecommendcall(calldate4);			
			SetRecommendCall.setrecommendGetreturnerrcode(dataStr4,201, 2012103 ,"推荐商品设置不能超过10个");
			//SQL查询置顶商品数量
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(10, coutistop, "校验置顶商品数量");
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productList.get(productList.size()-1));
				Logger.verifyEquals(false, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
				productList.forEach(ele->{
					try {
						NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ele,false);
					} catch (Exception e) {
						e.printStackTrace();
					}
				});
			}	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

		
	

//	@Test
//	@Category({P1.class})
//	@TestCase
//	public void Tc_SetRecommend_007() {
//		Logger.start(true,"子账号置顶商品");
//		try {
//			//TODO 补全case代码
//			Map user = getUser();
//			int sellerId = (Integer) user.get("sellerId");
//			String sellerName = (String) user.get("sellerName") ;
//			int sellerIdChild = (Integer) user.get("sellerId_Child");
//			String sellerNameChild = (String) user.get("sellerName_Child") ;
//			
//			//创建一个正在进行的直播
//			int activityId =createLiveing( sellerId,  sellerName);			
//			//发布一个立即上架商品
//			String productID = addNewProductOnSale( sellerId,  sellerName);
//			//将商品添加到直播
//			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
//			
//			//置顶商品
//			Map<String,Object> calldate = new HashMap<String, Object>();
//			calldate.put("UserId", sellerIdChild);
//			calldate.put("ActivityId", activityId);
//			calldate.put("ProductId", productID);
//			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
//			
//			//断言
//			SetRecommendCall.setrecommendGetreturncode(dataStr);
//			//SQL
//			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
//			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
//			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
//			Logger.verifyEquals(1, istopstatus, "校验SQL中是否置顶状态");
//			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
//			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
//			Logger.verifyEquals(1, coutistop, "校验置顶商品数量");
//			//Mango
//	        JSONObject aa=GetProductInfoByProductIdCall.GetProductInfoByProductId(productID);
//			JSONObject resultbymango = aa.getJSONObject("Data").getJSONObject("Product");
//			Boolean istopbymango = resultbymango.getJSONObject("LiveProduct").getBoolean("IsTop");
//			Logger.verifyEquals(true, istopbymango, "校验mango中是否置顶状态");
//			
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_008() {
		Logger.start(false,"非法的用户Id");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", 0);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
			SetRecommendCall.setrecommendGetreturnerrcode(dataStr,400 , 0 ,"非法的用户Id");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_009() {
		Logger.start(false,"非法的直播Id");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", 0);
			calldate.put("ProductId", productID);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
			SetRecommendCall.setrecommendGetreturnerrcode(dataStr,400 , 0 ,"非法的直播Id");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_010() {
		Logger.start(false,"商品Id不能为空");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", "");
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
			SetRecommendCall.setrecommendGetreturnerrcode(dataStr,400 , 0 ,"商品Id不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_011() {
		Logger.start(false,"商品不存在");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			
			//置顶商品
			Map<String,Object> calldate = new HashMap<String, Object>();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", "8389789798123");
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
			SetRecommendCall.setrecommendGetreturnerrcode(dataStr,201 , 2012102 ,"商品不存在");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetRecommend_012() {
		Logger.start(true,"置顶来源为app");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			calldate.put("OperationSource", 1);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);			
			
			//断言
			SetRecommendCall.setrecommendGetreturncode(dataStr);
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(1, istopstatus, "校验SQL中是否置顶状态");
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(1, coutistop, "校验置顶商品数量");
			//Mango
//	        JSONObject aa=GetProductInfoByProductIdCall.GetProductInfoByProductId(productID);
//			JSONObject resultbymango = aa.getJSONObject("Data").getJSONObject("Product");
//			Boolean istopbymango = resultbymango.getJSONObject("LiveProduct").getBoolean("IsTop");
//			Logger.verifyEquals(true, istopbymango, "校验mango中是否置顶状态");
			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMongo
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "校验oldmango中是否置顶状态");			
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productID,false);
			}	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}			
	
	/**
	 * 定义发布商品的sellerid sellername
	 * @return
	 */
	private static Map getUser() {
		HashMap  user = new HashMap();
		user.put("sellerId", Integer.valueOf(EnvSetup.getData("productsellerid")));
		user.put("sellerName", EnvSetup.getData("productsellername"));
		user.put("sellerId_Child", Integer.valueOf(EnvSetup.getData("productselleridChild")));
		user.put("sellerName_Child", EnvSetup.getData("productsellernameChild"));
		return user;		
	}	
	
	/**
	 * 创建一个正在执行的直播
	 * @return 直播id
	 * @throws Exception
	 */
	public static int createLiveing(int sellerId, String sellerName) throws Exception {
	    try {	    	
			//发布商品
			JSONObject createLiveInProgressObject = LiveCallService.createLiveInProgress(sellerName,sellerId);
			Logger.verifyEquals(createLiveInProgressObject.getInt("Code"), 200, "响应报文-返回码");
			//获取返回报文的ProductID值
			int activityId =  createLiveInProgressObject.getJSONObject("Data").getInt("ActivityId");
			Logger.verifyNotNull(activityId, "响应报文-直播ID");
			return activityId;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return (Integer) null;
	}
	
	/**
	 * 创建一个即将开始的直播
	 * @return 直播id
	 * @throws Exception
	 */
	public static int createLiveInFuture(int sellerId, String sellerName) throws Exception {
	    try {	    	
			//发布商品
			JSONObject createLiveInProgressObject = LiveCallService.createLiveBeginInFuture(sellerName,sellerId);
			Logger.verifyEquals(createLiveInProgressObject.getInt("Code"), 200, "响应报文-返回码");
			//获取返回报文的ProductID值
			int activityId =  createLiveInProgressObject.getJSONObject("Data").getInt("ActivityId");
			Logger.verifyNotNull(activityId, "响应报文-直播ID");
			return activityId;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return (Integer) null;
	}
	
		
	/**
	 * 发布一个立即上架商品
	 * @return 商品id
	 * @throws Exception
	 */
	public static String addNewProductOnSale(int sellerId, String sellerName) throws Exception {
	    try {	    	
			//发布商品
			JSONObject addNewProductOnSaleObject = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null);
			Logger.verifyEquals(addNewProductOnSaleObject.getInt("Code"), 200, "响应报文-返回码");
			//获取返回报文的ProductID值
			String productID =  addNewProductOnSaleObject.getJSONObject("Data").getString("ProductID");
			Logger.verifyNotNull(productID, "响应报文-商品ID");
			return productID;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return null;
	}
	
	
	/**
	 * 更新库存
	 * @param iNum 库存数量
	 * @param productID 商品id
	 * @return
	 * @throws Exception
	 */
	public static String updatestocknum(int iNum ,String productID) throws Exception {
	    try {	    	
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			int ret = ymtCatalogsIWapper.updatestocknumByCatalogId(iNum , productID);
//			return result;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return null;
	}
	
	/**
	 * 直播中商品开始销售
	 * @param sellerId
	 * @param activityId
	 * @param productID
	 * @throws Exception
	 */
	public static void productStartSale(int sellerId, int activityId, String productID) throws Exception {
		try{
			ActivityProductSaleBean activityproductsaleBean = new ActivityProductSaleBean();
			ActivityProductStartSaleCall activityproductstartsaleCall = new ActivityProductStartSaleCall();
			
			activityproductsaleBean.setActivityId(activityId);
			activityproductsaleBean.setUserId(sellerId);
			List<String> productIds = new ArrayList<>();
			productIds.add(productID);
			activityproductsaleBean.setProductIds(productIds);			
			activityproductstartsaleCall.setData(activityproductsaleBean);			
			activityproductstartsaleCall.callService();
			
			//获取返回报文的数据
			String dataStr = activityproductstartsaleCall.getReturnData();
			//返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");
			//断言"Code":200
			String code =  new JSONObject(dataStr).getString("Code");
			Logger.verifyIsContains(code, 200, "\"Code\":200");
			//断言"Msg":""
			String msg =  new JSONObject(dataStr).getString("Msg");
			Logger.verifyIsNull(msg, "Msg等于空");			
			
		}catch(Exception e){
			Logger.fail(e);
		}				
	}	
		
	
//	/***
//	 * 发布商品并申请参加活动
//	 * @param activityId
//	 * @return
//	 */
//	private String addNewProductAndApproveActivity(String activityId){
//		try{
//			//1.添加商品 -不上架
//			JSONObject productReqObject = SellerProductCallService.addNewProductNotOnSale(Integer.parseInt(sellerId), sellerName, null);
//			Logger.verifyEquals(productReqObject.getInt("Code"), 200, "响应报文-返回码");
//			
//			//获取返回报文的ProductID值
//			String productID =  productReqObject.getJSONObject("Data").getString("ProductID");
//			Logger.verifyNotNull(productID, "响应报文-商品ID");
//			
//			
//			//获取Catalogs id - SQL Ymt_Catalogs integratedproduct库
//			String catalogsID = new YmtCatalogsIWapper().selectCatalogsByProductId(productID).get(0).getsCatalogId();
//
//		
//			//todo 活动id
//			//2.参加活动 
//			JSONObject applyActivityRequest = ActivityCallService.applyProductInActivity(sellerId, productID, catalogsID, activityId);
//			Logger.verifyEquals(applyActivityRequest.getInt("Code"), 200, "响应报文-返回码");
//			
//			//查找productInActivityId
//			YmtProductsInActivityWapper ymtProductsInActivityWapper = new YmtProductsInActivityWapper();	
//			YmtProductsInActivity productsInActivity = ymtProductsInActivityWapper.selectByProductId(productID);
//			int productInActivityId = productsInActivity.getIproductinactivityid();
//			
//			//3. 开始活动二审
//			//3.1 登录活动后台获取cookie
//			List<String> loginCoList = ActivityCallService.getLoginCookieList(EnvSetup.getData("activityLoginName"), EnvSetup.getData("activityLoginPswd"));
//		
//			//3.2  审核通过
//			JSONObject approveProductRequest = ActivityCallService.approveProductInActivity(loginCoList, String.valueOf(productInActivityId), String.valueOf(activityId));		
//			
//			//验证审核通过
//			String msgStr = approveProductRequest.getString("success").equals("true")?"活动审核通过":"活动审核不通过";
//			Logger.comment(msgStr);
//			
//			return productID;
//		}catch(Exception e){
//			Logger.fail(e);
//		}
//		return "";				
//	}
	
}